﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;
using TiaoTaoHelper.Wtm.Units.EFCore;

#nullable disable

namespace HengTong.DataAccess.Migrations
{
    /// <inheritdoc />
    public partial class 员工档案增加所属公司 : TransactionalMigration
    {
        /// <inheritdoc />
        protected override void UpWithTransaction(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_SysPersonMedical_SysPersonMedicalExam_MedicalExamId",
                table: "SysPersonMedical");

            migrationBuilder.DropForeignKey(
                name: "FK_SysPersonTrainExam_SysPersonTrain_SysPersonTrainID",
                table: "SysPersonTrainExam");

            migrationBuilder.DropTable(
                name: "SysPersonMedicalExam");

            migrationBuilder.DropTable(
                name: "SysPersonTrain");

            migrationBuilder.AddColumn<Guid>(
                name: "OrgId",
                table: "SysPerson",
                type: "uniqueidentifier",
                nullable: true);

            migrationBuilder.CreateTable(
                name: "SysOrg",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Name = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Code = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    IsHrOrg = table.Column<bool>(type: "bit", nullable: false),
                    ParentId = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysOrg", x => x.ID);
                    table.ForeignKey(
                        name: "FK_SysOrg_SysOrg_ParentId",
                        column: x => x.ParentId,
                        principalTable: "SysOrg",
                        principalColumn: "ID");
                });

            migrationBuilder.CreateTable(
                name: "SysPersonMedicalBatche",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    BatchName = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: true),
                    MedicalType = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    Hospital = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: true),
                    MedicalDate = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Remark = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    UpdateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysPersonMedicalBatche", x => x.ID);
                });

            migrationBuilder.CreateTable(
                name: "SysPersonTrainBatche",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    TrainName = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: true),
                    TrainStartDate = table.Column<DateTime>(type: "datetime2", nullable: true),
                    TrainEndDate = table.Column<DateTime>(type: "datetime2", nullable: true),
                    ExamDate = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    UpdateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysPersonTrainBatche", x => x.ID);
                });

            migrationBuilder.CreateIndex(
                name: "IX_SysPerson_OrgId",
                table: "SysPerson",
                column: "OrgId");

            migrationBuilder.CreateIndex(
                name: "IX_SysOrg_ParentId",
                table: "SysOrg",
                column: "ParentId");

            migrationBuilder.AddForeignKey(
                name: "FK_SysPerson_SysOrg_OrgId",
                table: "SysPerson",
                column: "OrgId",
                principalTable: "SysOrg",
                principalColumn: "ID");

            migrationBuilder.AddForeignKey(
                name: "FK_SysPersonMedical_SysPersonMedicalBatche_MedicalExamId",
                table: "SysPersonMedical",
                column: "MedicalExamId",
                principalTable: "SysPersonMedicalBatche",
                principalColumn: "ID");

            migrationBuilder.AddForeignKey(
                name: "FK_SysPersonTrainExam_SysPersonTrainBatche_SysPersonTrainID",
                table: "SysPersonTrainExam",
                column: "SysPersonTrainID",
                principalTable: "SysPersonTrainBatche",
                principalColumn: "ID");
        }

        /// <inheritdoc />
        protected override void DownWithTransaction(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_SysPerson_SysOrg_OrgId",
                table: "SysPerson");

            migrationBuilder.DropForeignKey(
                name: "FK_SysPersonMedical_SysPersonMedicalBatche_MedicalExamId",
                table: "SysPersonMedical");

            migrationBuilder.DropForeignKey(
                name: "FK_SysPersonTrainExam_SysPersonTrainBatche_SysPersonTrainID",
                table: "SysPersonTrainExam");

            migrationBuilder.DropTable(
                name: "SysOrg");

            migrationBuilder.DropTable(
                name: "SysPersonMedicalBatche");

            migrationBuilder.DropTable(
                name: "SysPersonTrainBatche");

            migrationBuilder.DropIndex(
                name: "IX_SysPerson_OrgId",
                table: "SysPerson");

            migrationBuilder.DropColumn(
                name: "OrgId",
                table: "SysPerson");

            migrationBuilder.CreateTable(
                name: "SysPersonMedicalExam",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    BatchName = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: true),
                    CreateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Hospital = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: true),
                    MedicalDate = table.Column<DateTime>(type: "datetime2", nullable: true),
                    MedicalType = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    Remark = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
                    UpdateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysPersonMedicalExam", x => x.ID);
                });

            migrationBuilder.CreateTable(
                name: "SysPersonTrain",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    CreateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    ExamDate = table.Column<DateTime>(type: "datetime2", nullable: true),
                    TrainEndDate = table.Column<DateTime>(type: "datetime2", nullable: true),
                    TrainName = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: true),
                    TrainStartDate = table.Column<DateTime>(type: "datetime2", nullable: true),
                    UpdateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysPersonTrain", x => x.ID);
                });

            migrationBuilder.AddForeignKey(
                name: "FK_SysPersonMedical_SysPersonMedicalExam_MedicalExamId",
                table: "SysPersonMedical",
                column: "MedicalExamId",
                principalTable: "SysPersonMedicalExam",
                principalColumn: "ID");

            migrationBuilder.AddForeignKey(
                name: "FK_SysPersonTrainExam_SysPersonTrain_SysPersonTrainID",
                table: "SysPersonTrainExam",
                column: "SysPersonTrainID",
                principalTable: "SysPersonTrain",
                principalColumn: "ID");
        }
    }
}
